package com.ruoyi.web.controller.wb;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.wb.domain.WbClassifyYear;
import com.ruoyi.wb.dto.WbClassifyDelDto;
import com.ruoyi.wb.dto.WbClassifyDto;
import com.ruoyi.wb.dto.WbClassifyYearDto;
import com.ruoyi.wb.service.IWbClassifyYearService;
import com.ruoyi.wb.vo.WbClassifyYearVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 维保年度类目列表Controller
 * 
 * @author ruoyi
 * @date 2024-11-18
 */
@RestController
@RequestMapping("/system/WbClassifyYear")
public class WbClassifyYearController extends BaseController
{
    @Autowired
    private IWbClassifyYearService wbClassifyYearService;

    /**
     * 查询维保年度类目列表列表
     */
    @GetMapping("/list")
    public TableDataInfo list(WbClassifyYear wbClassifyYear)
    {
        startPage();
        List<WbClassifyYear> list = wbClassifyYearService.selectWbClassifyYearList(wbClassifyYear);
        return getDataTable(list);
    }

    /**
     * 查询维保年度类目列表列表
     */
    @GetMapping("/allList")
    public TableDataInfo allList(WbClassifyYear wbClassifyYear)
    {
        startPage();
        List<WbClassifyYearVo> list = wbClassifyYearService.allList(wbClassifyYear);
        TableDataInfo dataTable = getDataTable(list);
        dataTable.setTotal(wbClassifyYearService.selectWbClassifyYearList(wbClassifyYear).size());
        return dataTable;
    }

    /**
     * 导出维保年度类目列表列表
     */
    @Log(title = "维保年度类目列表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WbClassifyYear wbClassifyYear)
    {
        List<WbClassifyYear> list = wbClassifyYearService.selectWbClassifyYearList(wbClassifyYear);
        ExcelUtil<WbClassifyYear> util = new ExcelUtil<WbClassifyYear>(WbClassifyYear.class);
        util.exportExcel(response, list, "维保年度类目列表数据");
    }

    /**
     * 获取维保年度类目列表详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(wbClassifyYearService.selectWbClassifyYearById(id));
    }

    /**
     * 新增维保年度类目列表
     */
    @Log(title = "维保年度类目列表", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WbClassifyYear wbClassifyYear)
    {
        return toAjax(wbClassifyYearService.insertWbClassifyYear(wbClassifyYear));
    }

    /**
     * 修改维保年度类目列表
     */
    @Log(title = "维保年度类目列表", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WbClassifyYear wbClassifyYear)
    {
        return toAjax(wbClassifyYearService.updateWbClassifyYear(wbClassifyYear));
    }

    /**
     * 删除维保年度类目列表
     */
    @Log(title = "维保年度类目列表", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(wbClassifyYearService.deleteWbClassifyYearByIds(ids));
    }

    /**
     * 新增维保年度类目列表
     */
    @Log(title = "维保年度类目列表", businessType = BusinessType.INSERT)
    @PostMapping("/addAll")
    public AjaxResult addAll(@RequestBody WbClassifyYearDto wbClassifyYearDto)
    {
        return toAjax(wbClassifyYearService.addAll(wbClassifyYearDto));
    }

    /**
     * 新增模板 一级 或二级 或三级
     */
    @PostMapping("/addOne")
    public AjaxResult addOne(@RequestBody WbClassifyDto wbClassifyDto)
    {
        return toAjax(wbClassifyYearService.addOne(wbClassifyDto));
    }

    //修改模板 一级二级或三级
    @PutMapping("/editOne")
    public AjaxResult editOne(@RequestBody WbClassifyDto wbClassifyDto)
    {
        return toAjax(wbClassifyYearService.editOne(wbClassifyDto));
    }

    /**
     * 批量删除维保年度类目列表
     */
    @Log(title = "维保年度类目列表", businessType = BusinessType.DELETE)
    @DeleteMapping("/removeAll")
    public AjaxResult removeAll(@RequestBody WbClassifyDelDto wbClassifyDelDto)
    {
        return toAjax(wbClassifyYearService.removeAll(wbClassifyDelDto));
    }

}
